package net.jeeshop.core.oscache;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import net.jeeshop.core.FrontContainer;
import net.jeeshop.core.KeyValueHelper;
import net.jeeshop.core.ManageContainer;
import net.jeeshop.core.front.SystemManager;
import net.jeeshop.core.pay.alipay.alipayescow.config.AlipayConfig;
import net.jeeshop.core.util.DateTimeUtil;
import net.jeeshop.services.front.advert.AdvertService;
import net.jeeshop.services.front.advert.bean.Advert;
import net.jeeshop.services.front.area.AreaService;
import net.jeeshop.services.front.area.bean.Area;
import net.jeeshop.services.front.attribute.AttributeService;
import net.jeeshop.services.front.attribute.bean.Attribute;
import net.jeeshop.services.front.catalog.CatalogService;
import net.jeeshop.services.front.catalog.bean.Catalog;
import net.jeeshop.services.front.comment.CommentService;
import net.jeeshop.services.front.commentType.CommentTypeService;
import net.jeeshop.services.front.commentType.bean.CommentType;
import net.jeeshop.services.front.express.ExpressService;
import net.jeeshop.services.front.express.bean.Express;
import net.jeeshop.services.front.indexImg.IndexImgService;
import net.jeeshop.services.front.indexImg.bean.IndexImg;
import net.jeeshop.services.front.keyvalue.KeyvalueService;
import net.jeeshop.services.front.keyvalue.bean.Keyvalue;
import net.jeeshop.services.front.navigation.NavigationService;
import net.jeeshop.services.front.navigation.bean.Navigation;
import net.jeeshop.services.front.news.NewsService;
import net.jeeshop.services.front.news.bean.News;
import net.jeeshop.services.front.notifyTemplate.NotifyTemplateService;
import net.jeeshop.services.front.notifyTemplate.bean.NotifyTemplate;
import net.jeeshop.services.front.order.OrderService;
import net.jeeshop.services.front.pay.PayService;
import net.jeeshop.services.front.pay.bean.Pay;
import net.jeeshop.services.front.product.ProductService;
import net.jeeshop.services.front.product.bean.Product;
import net.jeeshop.services.front.product.bean.ProductStockInfo;
import net.jeeshop.services.front.systemSetting.SystemSettingService;
import net.jeeshop.services.front.systemSetting.bean.SystemSetting;
import net.jeeshop.services.manage.accountRank.AccountRankService;
import net.jeeshop.services.manage.accountRank.bean.AccountRank;
import net.jeeshop.services.manage.activity.ActivityService;
import net.jeeshop.services.manage.activity.bean.Activity;
import net.jeeshop.services.manage.hotquery.HotqueryService;
import net.jeeshop.services.manage.hotquery.bean.Hotquery;
import net.jeeshop.services.manage.oss.OssService;
import net.jeeshop.services.manage.oss.bean.AliyunOSS;
import net.jeeshop.services.manage.oss.bean.Oss;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
public class FrontCache {
    private static final Logger logger = LoggerFactory.getLogger(FrontCache.class);
    private KeyvalueService keyvalueService;
    private SystemSettingService systemSettingService;
    private NewsService newsService;
    private CatalogService catalogService;
    private IndexImgService indexImgService;
    private NavigationService navigationService;
    private AttributeService attributeService;
    private PayService payService;
    private CommentTypeService commentTypeService;
    private AreaService areaService;
    private ExpressService expressService;
    private AdvertService advertService;
    private NotifyTemplateService notifyTemplateService;
    private OssService ossService;
    private OrderService orderService;
    private CommentService commentService;
    private AccountRankService accountRankService;
    private ActivityService activityService;
    private HotqueryService hotqueryService;
    private ProductService productService;
    public HotqueryService getHotqueryService() {
        return hotqueryService;
    }
    public void setHotqueryService(HotqueryService hotqueryService) {
        this.hotqueryService = hotqueryService;
    }
    public ActivityService getActivityService() {
        return activityService;
    }
    public void setActivityService(ActivityService activityService) {
        this.activityService = activityService;
    }
    public AccountRankService getAccountRankService() {
        return accountRankService;
    }
    public void setAccountRankService(AccountRankService accountRankService) {
        this.accountRankService = accountRankService;
    }
    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }
    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;
    }
    public void setNotifyTemplateService(NotifyTemplateService notifyTemplateService) {
        this.notifyTemplateService = notifyTemplateService;
    }
    public void setAdvertService(AdvertService advertService) {
        this.advertService = advertService;
    }
    public void setExpressService(ExpressService expressService) {
        this.expressService = expressService;
    }
    public void setAreaService(AreaService areaService) {
        this.areaService = areaService;
    }
    public void setPayService(PayService payService) {
        this.payService = payService;
    }
    public void setCommentTypeService(CommentTypeService commentTypeService) {
        this.commentTypeService = commentTypeService;
    }
    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }
    public void setIndexImgService(IndexImgService indexImgService) {
        this.indexImgService = indexImgService;
    }
    public void setAttributeService(AttributeService attributeService) {
        this.attributeService = attributeService;
    }
    public void setSystemSettingService(
            SystemSettingService systemSettingService) {
        this.systemSettingService = systemSettingService;
    }
    public void setCatalogService(CatalogService catalogService) {
        this.catalogService = catalogService;
    }
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }
    public void setNavigationService(NavigationService navigationService) {
        this.navigationService = navigationService;
    }
    public void setKeyvalueService(KeyvalueService keyvalueService) {
        this.keyvalueService = keyvalueService;
    }
    public void loadKeyValue() {
        logger.info("load...");
        KeyValueHelper.load(keyvalueService.selectList(new Keyvalue()));
    }
    public void loadSystemSetting() {
        SystemManager.systemSetting = systemSettingService.selectOne(new SystemSetting());
        if(SystemManager.systemSetting==null){
        }
        if(StringUtils.isNotBlank(SystemManager.systemSetting.getImages())){
            String[] images
                    = SystemManager.systemSetting.getImages().split(ManageContainer.product_images_spider);
            if(SystemManager.systemSetting.getImagesList()==null){
                SystemManager.systemSetting.setImagesList(new LinkedList<String>());
            }else{
                SystemManager.systemSetting.getImagesList().clear();
            }
            for(int i=0;i<images.length;i++){
                SystemManager.systemSetting.getImagesList().add(images[i]);
            }
        }
        if(StringUtils.isNotBlank(SystemManager.systemSetting.getBelieveLoginConfig())){
            SystemManager.systemSetting.setBelieveLoginInfo(JSON.parseObject(SystemManager.systemSetting.getBelieveLoginConfig(), BelieveLoginInfo.class));
        }
    }
    private static void setBucketPublicReadable(OSSClient client, String bucketName)
            throws OSSException, ClientException {
        client.createBucket(bucketName);
        client.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
    }
    class NameComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                return ((String)hashA.get("filename")).compareTo((String)hashB.get("filename"));
            }
        }
    }
    class SizeComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                if (((Long)hashA.get("filesize")) > ((Long)hashB.get("filesize"))) {
                    return 1;
                } else if (((Long)hashA.get("filesize")) < ((Long)hashB.get("filesize"))) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }
    public void loadPlugConfig() {
        Pay pay = new Pay();
        pay.setCode(Pay.pay_code_alipayescow);
        pay = payService.selectOne(pay);
        SystemManager.alipayConfig = pay.getSeller();
        AlipayConfig.partner = pay.getPartner();
        AlipayConfig.key = pay.getKey1();
        logger.error("SystemManager.alipayConfig="+SystemManager.alipayConfig);
        CommentType commentType = new CommentType();
        commentType.setStatus(CommentType.commentType_status_y);
        commentType = commentTypeService.selectOne(commentType);
        SystemManager.commentTypeCode = commentType.getCode();
        logger.error("SystemManager.commentTypeCode="+SystemManager.commentTypeCode);
    }
    public void loadAttributeList() {
        List<Attribute> attrs = attributeService.selectList(new Attribute());
        SystemManager.attrs = attrs;
        if(attrs!=null && attrs.size()>0){
            Map<String, Integer> map = new HashMap<String, Integer>();
            SystemManager.attrsMap.clear();
            for(int i=0;i<attrs.size();i++){
                Attribute mainAttr = attrs.get(i);
                if(mainAttr.getPid()==0){
                    map.put(mainAttr.getId(), mainAttr.getCatalogID());
                }else{
                    Attribute newAttr = new Attribute();
                    newAttr.setPid(mainAttr.getPid());
                    SystemManager.attrsMap.put(mainAttr.getId(), newAttr);
                }
            }
            if(map.size()>0){
                for(Iterator<Entry<String, Attribute>> it =
                    SystemManager.attrsMap.entrySet().iterator();it.hasNext();){
                    Entry<String, Attribute> entry = it.next();
                    String id = String.valueOf(entry.getValue().getPid());
                    logger.error("id="+id);
                    if(map.get(id)!=null){
                        entry.getValue().setCatalogID(map.get(id));
                    }
                }
                logger.error("SystemManager.attrsMap="+SystemManager.attrsMap);
                logger.error("SystemManager.attrsMap(63) = "+SystemManager.attrsMap.get("63"));
            }
        }
    }
    public void loadNewCatalogs() {
        Catalog c = new Catalog();
        c.setType("a");
        c.setPid("0");
        List<Catalog> newCatalogs = catalogService.selectList(c);
        if(newCatalogs!=null && newCatalogs.size()>0){
            for(int i=0;i<newCatalogs.size();i++){
                Catalog item = newCatalogs.get(i);
                News news = new News();
                news.setCatalogID(item.getId());
                List<News> newsList = newsService.selectList(news);
                item.setNews(newsList);
            }
        }
        SystemManager.newCatalogs = newCatalogs;
    }
    public void loadNews() {
        List<News> news = newsService.selectList(new News());
        if(news!=null && news.size()>0){
            SystemManager.newsMap.clear();
            for(int i=0;i<news.size();i++){
                News newsObj = news.get(i);
                SystemManager.newsMap.put(newsObj.getCode(),newsObj);
            }
        }
    }
    public static List<Catalog> loadCatalogChildren(String catalogID) {
        try {
            logger.error(">>catalogID="+catalogID);
            if(StringUtils.isBlank(catalogID)){
                throw new NullPointerException();
            }
            Catalog catalog = SystemManager.catalogsMap.get(catalogID);
            if(catalog==null){
                throw new NullPointerException();
            }
            if(catalog.getPid().equals("0")){
                if(catalog.getChildren()==null){
                }else{
                }
                return catalog.getChildren();
            }else{
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String getPid(String catalogID){
        if(StringUtils.isBlank(catalogID)){
            throw new NullPointerException();
        }
        Catalog catalog = SystemManager.catalogsMap.get(catalogID);
        if(catalog==null){
            throw new NullPointerException();
        }
        if(catalog.getPid().equals("0")){
            return catalog.getId();
        }else{
            catalog = SystemManager.catalogsMap.get(catalog.getPid());
            return catalog.getId();
        }
    }
    private static void setBucketPublicReadable(OSSClient client, String bucketName)
            throws OSSException, ClientException {
        client.createBucket(bucketName);
        client.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
    }
    class NameComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                return ((String)hashA.get("filename")).compareTo((String)hashB.get("filename"));
            }
        }
    }
    class SizeComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                if (((Long)hashA.get("filesize")) > ((Long)hashB.get("filesize"))) {
                    return 1;
                } else if (((Long)hashA.get("filesize")) < ((Long)hashB.get("filesize"))) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }
    public static List<Attribute> loadAttrByCatalogID(int catalogID) {
        if (SystemManager.attrs == null || SystemManager.attrs.size() == 0) {
            return null;
        }
        List<Attribute> attrs = new LinkedList<Attribute>();
        for (int i = 0; i < SystemManager.attrs.size(); i++) {
            Attribute attr = SystemManager.attrs.get(i);
            if (attr.getPid() == -1) {
                continue;
            }
            if (attr.getCatalogID() == catalogID) {
                attrs.add(attr);
                attr.getAttrList().clear();
                int id = Integer.valueOf(attr.getId());
                for (int j = 0; j < SystemManager.attrs.size(); j++) {
                    Attribute attr2 = SystemManager.attrs.get(j);
                    if (attr2.getPid() == id) {
                        attr.getAttrList().add(attr2);
                    }
                }
            }
        }
        logger.error("attrs=" + attrs);
        return attrs;
    }
    public void loadCatalogs(boolean loadProduct) throws Exception {
        logger.info("load...");
        Catalog c = new Catalog();
        c.setType("p");
        c.setPid("0");
        List<Catalog> catalogs = catalogService.loadRoot(c);
        System.out.println("result:" + catalogs);
        SystemManager.catalogs = catalogs;
        loadCatalogs2();
        loadCatalogs2("p",SystemManager.catalogs);
        loadCatalogs2("a",SystemManager.catalogsArticle);
        logger.error("SystemManager.catalogs="+SystemManager.catalogs.size());
        logger.error("SystemManager.catalogsArticle="+SystemManager.catalogsArticle.size());
        SystemManager.catalogsMap.clear();
        SystemManager.catalogsCodeMap.clear();
        putToMap(SystemManager.catalogs,loadProduct);
    }
    public void putToMap(List<Catalog> catalogs,boolean loadProduct) throws Exception{
        if(catalogs==null || catalogs.size()==0){
            return;
        }
        for(int i=0;i<catalogs.size();i++){
            Catalog item = catalogs.get(i);
            if(loadProduct){
                loadsuperMenuProducts(item);
                loadHotProductByCatalog(item);
            }
            SystemManager.catalogsMap.put(item.getId(),item);
            if(SystemManager.catalogsCodeMap.get(item.getCode())!=null){
                logger.error("item.code = " + item.getCode());
            }
            SystemManager.catalogsCodeMap.put(item.getCode(),item);
            if(item.getChildren()!=null && item.getChildren().size()>0){
                putToMap(item.getChildren(),loadProduct);
            }
        }
    }
    private void loadsuperMenuProducts(Catalog item){
        if(!item.getPid().equals("0")){
            return;
        }
        if(item.getChildren()==null || item.getChildren().size()==0){
            return;
        }
        List<String> ids = new LinkedList<String>();
        for(int j=0;j<item.getChildren().size();j++){
            ids.add(item.getChildren().get(j).getId());
        }
        Product product = new Product();
        product.setTop(3);
        product.setProductIds(ids);
        List<Product> superMenuProducts = productService.loadHotProductShowInSuperMenu(product);
        if(superMenuProducts==null || superMenuProducts.size()==0){
            logger.error("superMenuProducts = 0" + ",catalogCode = " + item.getCode());
        }else{
            logger.error("superMenuProducts = " + superMenuProducts.size()  + ",catalogCode = " +
                    item.getCode());
        }
        if(superMenuProducts!=null && superMenuProducts.size()>0){
            item.setSuperMenuProducts(superMenuProducts);
        }
    }
    private void loadHotProductByCatalog(Catalog item){
        if(item.getPid().equals("0") && (item.getChildren()==null || item.getChildren().size()==0)){
            return;
        }
        Product p = new Product();
        p.setTop(FrontContainer.default_page_left_product_size);
        if(item.getPid().equals("0")){
            List<Integer> ids = new LinkedList<Integer>();
            for(int j=0;j<item.getChildren().size();j++){
                ids.add(Integer.valueOf(item.getChildren().get(j).getId()));
            }
            p.setQueryCatalogIDs(ids);
        }else{
            p.setCatalogID(item.getId());
        }
        List<Product> hotProducts = productService.selectPageLeftHotProducts(p);
        if(hotProducts==null || hotProducts.size()==0){
            logger.error("loadHotProductByCatalog.hotProducts = 0" + ",catalogCode = " +
                    item.getCode());
        }else{
            logger.error("loadHotProductByCatalog.hotProducts = " + hotProducts.size()  +
                    ",catalogCode = " + item.getCode());
        }
        if(hotProducts!=null && hotProducts.size()>0){
            item.setHotProducts(hotProducts);
        }
    }
    private void loadCatalogs2(String type,List<Catalog> catalogs){
        Catalog cc = new Catalog();
        cc.setType(type);
        List<Catalog> catalogsList = catalogService.selectList(cc);
        if(catalogsList!=null){
            Map<String, Catalog> map = new HashMap<String, Catalog>();
            for(Iterator<Catalog> it = catalogsList.iterator();it.hasNext();){
                Catalog item = it.next();
                if(StringUtils.isNotBlank(item.getPid()) && item.getPid().equals("0")){
                    if(item.getShowInNav().equals(Catalog.catalog_showInNav_y)){
                        item.setShowInNavStr("");
                    }
                    map.put(item.getId(), item);
                    it.remove();
                }
            }
            for(Iterator<Catalog> it = catalogsList.iterator();it.hasNext();){
                Catalog item = it.next();
                if(StringUtils.isNotBlank(item.getPid())){
                    list.add(item);
                    Catalog rootItem = map.get(item.getPid());
                    if(rootItem!=null){
                        if(rootItem.getChildren()==null){
                            rootItem.setChildren(new LinkedList<Catalog>());
                        }
                        rootItem.getChildren().add(item);
                    }
                    it.remove();
                }
            }
            if(catalogs==null){
                catalogs = new LinkedList<Catalog>();
            }else{
                catalogs.clear();
            }
            for(Iterator<Entry<String, Catalog>> it = map.entrySet().iterator();it.hasNext();){
                catalogs.add(it.next().getValue());
            }
            Collections.sort(catalogs, new Comparator<Catalog>() {
                public int compare(Catalog o1, Catalog o2) {
                    if (o1.getOrder1() > o2.getOrder1()) {
                        return 1;
                    } else if (o1.getOrder1() < o2.getOrder1()) {
                        return -1;
                    }
                    return 0;
                }
            });
            for(int i=0;i<catalogs.size();i++){
                if(catalogs.get(i).getChildren()==null){
                    continue;
                }
                Collections.sort(catalogs.get(i).getChildren(), new Comparator<Catalog>() {
                    public int compare(Catalog o1, Catalog o2) {
                        if (o1.getOrder1() > o2.getOrder1()) {
                            return 1;
                        } else if (o1.getOrder1() < o2.getOrder1()) {
                            return -1;
                        }
                        return 0;
                    }
                });
            }
        }
    }
    public void loadIndexImgs() {
        logger.info("loadIndexImgs...");
        IndexImg c = new IndexImg();
        SystemManager.indexImages = indexImgService.selectList(c);
    }
    public void selectTopProducts() {
        Product e = new Product();
        e.setStatus(1);
        e.setTop(8);
        List<Product> result = productService.selectList(e);
        if (result == null || result.size() == 0) {
            return;
        }
        System.out.println("result=" + result);
        List<List<Product>> list = new LinkedList<List<Product>>();
        int nn = 0;
        int maxLen = 4;
        int i = 0;
        List<Product> row = new LinkedList<Product>();
        for (Iterator<Product> it = result.iterator(); it.hasNext();) {
            Product ee = (Product) it.next();
            row.add(ee);
            nn++;
            i++;
            if (nn == maxLen) {
                list.add(row);
                nn = 0;
                row = new LinkedList<Product>();
            }
            if ((result.size() == 1 + i)) {
                if (row.size() == 0) {
                    row.add(ee);
                }
                list.add(row);
                break;
            }
        }
        SystemManager.goodsTopList = list; productTypeService.selectList(e);
        System.out.println("list====" + list);
    }
    public void loadNavigations() {
        logger.info("load...");
        Navigation nav = new Navigation();
        nav.setPosition("bottom");
        List<Navigation> navigations = navigationService.selectList(nav);
        SystemManager.navigations = navigations;
    }
    public void loadProductsShowInIndex() {
        SystemManager.newProducts = loadProducts(1);
        SystemManager.saleProducts = loadProducts(2);
        SystemManager.hotProducts = loadProducts(3);
    }
    public void loadSuijiProducts() {
        SystemManager.suijiProducts = loadProducts(2);
        Product p = new Product();
        p.setTop(10);
        SystemManager.suijiProducts = productService.selectList(p);
    }
    private List<Product> loadProducts(int type) {
        Product p = new Product();
        p.setTop(8);
        if (type == 1) {
            p.setIsnew(Product.Product_isnew_y);
        } else if (type == 2) {
            p.setSale(Product.Product_sale_y);
        } else if (type == 3) {
            p.setHot(true);
        }
        return productService.selectList(p);
    }
    private void loadNotices() {
        Notice notice = new Notice(7);
        notice.setOffset(0);
        notice.setPageSize(7);
        SystemManager.noticeList = noticeService.selectList(notice);
        News news = new News();
        news.setOffset(0);
        news.setPageSize(7);
        SystemManager.noticeList = newsService.selectNoticeList(news);
    }
    public void loadProductStock() {
        List<ProductStockInfo> list = productService.selectStockList(new Product());
        synchronized (SystemManager.product_stock_lock) {
            if(SystemManager.productStockMap==null){
                SystemManager.productStockMap = new ConcurrentHashMap<String,
                        ProductStockInfo>(list.size());
            }else{
                SystemManager.productStockMap.clear();
            }
            if(list!=null && list.size()>0){
                for(int i=0;i<list.size();i++){
                    ProductStockInfo p = list.get(i);
                    SystemManager.productStockMap.put(p.getId(), p);
                }
            }
        }
    }
    private void loadHotProductShowInSuperMenu(){
        for(int i=0;i<SystemManager.catalogs.size();i++){
            Catalog item = SystemManager.catalogs.get(i);
            if(item.getChildren()==null || item.getChildren().size()==0){
                continue;
            }
            List<String> ids = new LinkedList<String>();
            for(int j=0;j<item.getChildren().size();j++){
                ids.add(item.getChildren().get(j).getId());
            }
            Product product = new Product();
            product.setTop(3);
            product.setCatalogID(item.getId());
            product.setProductIds(ids);
            List<Product> superMenuProducts = productService.loadHotProductShowInSuperMenu(product);
            if(superMenuProducts==null || superMenuProducts.size()==0){
                logger.error("superMenuProducts = 0");
            }else{
                logger.error("superMenuProducts = " + superMenuProducts.size());
            }
            if(superMenuProducts!=null && superMenuProducts.size()>0){
                item.setSuperMenuProducts(superMenuProducts);
            }
        }
    }
    private void loadIndexLeftProduct(){
        Product p = new Product();
        p.setTop(FrontContainer.default_page_left_product_size);
        SystemManager.indexLeftProduct = productService.selectPageLeftHotProducts(p);
    }
    public void loadActivityProductList(){
        SystemManager.activityProductMap.clear();
        if(SystemManager.activityMap.size()==0){
            return;
        }
        List<Product> list = productService.selectActivityProductList(null);
        if(list==null){
            logger.error("loadActivityProductList.list=0");
        }else{
            logger.error("loadActivityProductList.list="+list.size());
            for(int i=0;i<list.size();i++){
                Product p = list.get(i);
                Activity activity = SystemManager.activityMap.get(p.getActivityID());
                if(activity==null){
                    logger.error(" p = " + p.getId());
                    continue;
                }
                if(activity.getActivityType().equals(Activity.activity_activityType_c)){
                    if(activity.getDiscountType().equals(Activity.activity_discountType_r)){
                        addProductByDiscountType(p,activity);
                    }else if(activity.getDiscountType().equals(Activity.activity_discountType_d)){
                        addProductByDiscountType(p,activity);
                    }else if(activity.getDiscountType().equals(Activity.activity_discountType_s)){
                        addProductByDiscountType(p,activity);
                    }
                }
            }
        }
    }
    private void addProductByDiscountType(Product p,Activity activity) {
        List<Product> valueList = SystemManager.activityProductMap.get(activity.getDiscountType());
        if(valueList == null){
            valueList = new LinkedList<Product>();
            SystemManager.activityProductMap.put(activity.getDiscountType(), valueList);
        }
        p.setFinalPrice(String.valueOf(p.caclFinalPrice()));
        p.setExpire(activity.isExpire());
        p.setActivityEndDateTime(activity.getEndDate());activity.getActivityEndDateTime());
        p.setDiscountFormat(activity.getDiscountFormat());
        p.setMaxSellCount(activity.getMaxSellCount());
        valueList.add(p);
    }
    private String intercept0(ActionInvocation actionInvocation) throws Exception {
        String actionName = actionInvocation.getProxy().getActionName();
        Object action = actionInvocation.getProxy().getAction();
        String method = actionInvocation.getProxy().getMethod();
        String namespace = actionInvocation.getProxy().getNamespace();
        Object action2 = actionInvocation.getAction();
        if(StringUtils.isBlank(method)){
            throw new NullPointerException;
        }		logger.error(">>ManageInterceptor==actionName="+actionName+";method="+method+";action="+action+";namespace="+namespace);
        logger.error(">>ManageInterceptor==actionName="+actionName+";method="+method+";action="+action+";namespace="+namespace+";action2="+action2);
        String url = actionName+"!"+method+".action";
        StringBuffer urlBuff = new StringBuffer(actionName);
        urlBuff.append("!").append(method).append(".action");
        actionInvocation.getInvocationContext().
        if (action2 instanceof UserAction || action2 instanceof MenuAction) {
            return actionInvocation.invoke();
        }
    public void loadActivityScoreProductList(){
        logger.error("loadActivityScoreProductList...");
        if(SystemManager.activityMap.size()==0){
            return;
        }
        List<String> productIds = new LinkedList<String>();
        for(Iterator<Entry<String, Activity>> it =
            SystemManager.activityMap.entrySet().iterator();it.hasNext();){
            Entry<String, Activity> entry = it.next();
            if(entry.getValue().getActivityType().equals(Activity.activity_activityType_j) &&
                    StringUtils.isNotBlank(entry.getValue().getProductID())){
                String[] arr = entry.getValue().getProductID().split("\\|");
                for(int i=0;i<arr.length;i++){
                    productIds.add(arr[i]);
                }
            }
        }
        logger.error("loadActivityScoreProductList...productIds="+productIds.toString());
        if(productIds.size()>0){
            Product queryProduct = new Product();
            queryProduct.setProductIds(productIds);
            SystemManager.activityScoreProductList =
                    productService.selectActivityProductList(queryProduct);
            for(int i=0;i<SystemManager.activityScoreProductList.size();i++){
                Product p = SystemManager.activityScoreProductList.get(i);
                Activity activity = SystemManager.activityMap.get(p.getActivityID());
                if(activity==null){
                    logger.error(" p = " + p.getId());
                    continue;
                }
                if(!activity.getActivityType().equals(Activity.activity_activityType_c)){
                    p.setExchangeScore(activity.getExchangeScore());
                    p.setExpire(activity.isExpire());
                    p.setActivityEndDateTime(activity.getEndDate());activity.getActivityEndDateTime());
                    p.setDiscountFormat(activity.getDiscountFormat());
                    p.setMaxSellCount(activity.getMaxSellCount());
                }
            }
        }
    }
    public void loadActivityTuanProductList(){
        logger.error("loadActivityTuanProductList...");
        if(SystemManager.activityMap.size()==0){
            return;
        }
        List<String> productIds = new LinkedList<String>();
        for(Iterator<Entry<String, Activity>> it =
            SystemManager.activityMap.entrySet().iterator();it.hasNext();){
            Entry<String, Activity> entry = it.next();
            if(entry.getValue().getActivityType().equals(Activity.activity_activityType_t) &&
                    StringUtils.isNotBlank(entry.getValue().getProductID())){
                String[] arr = entry.getValue().getProductID().split("\\|");
                for(int i=0;i<arr.length;i++){
                    productIds.add(arr[i]);
                }
            }
        }
        logger.error("loadActivityScoreProductList...productIds="+productIds.toString());
        if(productIds.size()>0){
            Product queryProduct = new Product();
            queryProduct.setProductIds(productIds);
            SystemManager.activityTuanProductList =
                    productService.selectActivityProductList(queryProduct);
            for(int i=0;i<SystemManager.activityTuanProductList.size();i++){
                Product p = SystemManager.activityTuanProductList.get(i);
                Activity activity = SystemManager.activityMap.get(p.getActivityID());
                if(activity==null){
                    logger.error(" p = " + p.getId());
                    continue;
                }
                if(activity.getActivityType().equals(Activity.activity_activityType_t)){
                    p.setExchangeScore(activity.getExchangeScore());
                    p.setExpire(activity.isExpire());
                    p.setActivityEndDateTime(activity.getEndDate());activity.getActivityEndDateTime());
                    p.setDiscountFormat(activity.getDiscountFormat());
                    p.setMaxSellCount(activity.getMaxSellCount());
                    p.setMinGroupCount(activity.getMinGroupCount());
                    p.setTuanPrice(activity.getTuanPrice());
                    p.setHasBuyGroupPerson(3212);activity.getHasBuyGroupPerson());
                }
            }
        }
    }
    public void loadActivityMap(){
        SystemManager.activityMap.clear();
        List<Activity> list = activityService.selectList(new Activity());
        if(list!=null){
            for(int i=0;i<list.size();i++){
                Activity activity = list.get(i);
                activity.setExpire(activity.checkActivity());
                if(!activity.isExpire()){
                    activity.setActivityEndDateTime(DateTimeUtil.getActivityEndDateTimeString(activity.getEndDate()));
                }
                if(activity.getDiscountType().equals(Activity.activity_discountType_d)){
                    activity.setDiscountFormat(String.valueOf(Double.valueOf(activity.getDiscount()) / 10D));
                }
                SystemManager.activityMap.put(activity.getId(), activity);
            }
        }
    }
    public void loadHotquery(){
        SystemManager.hotqueryList = hotqueryService.selectList(new Hotquery());
    }
    public void loadAllCache() throws Exception {
        logger.error("loadAllCache...");
        loadHotquery();
        loadCatalogs(true);
        loadIndexLeftProduct();
        loadAttributeList();
        loadIndexImgs();
        loadKeyValue();
        loadNavigations();
        loadSystemSetting();
        loadPlugConfig();
        loadArea();
        loadExpress();
        loadAdvertList();
        loadNewCatalogs();
        loadNews();
        loadHotProducts();
        loadNewProducts();
        loadSaleProducts();
        loadSuijiProducts();
        loadProductsShowInIndex();
        loadNotices();
        loadProductStock();
        loadAccountRank();
        loadHotSearch();
        readJsonArea();
        loadNotifyTemplate();
        loadActivityMap();
        loadActivityProductList();
        loadActivityScoreProductList();
        loadActivityTuanProductList();
        logger.error;
    }
    public static void main(String[] args) {
        String str = "10280|10281|10282";
        String[] arr = str.split("\\|");
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
    }
}